<?php

use \Welcomescreen\Agavi\View;

class Frontend_DeliverTemplateResourceSuccessView extends View\FrontendBaseView {
	
	/**
	 * @parameter  \AgaviRequestDataHolder $rd
	 * @return     mixed
	 */
	public function executeResource(\AgaviRequestDataHolder $rd) {
		$filePath = $this->getAttribute('filePath');
		$finfo = finfo_open(FILEINFO_MIME_TYPE);
		$mimeType = finfo_file($finfo, $filePath);
		finfo_close($finfo);
		
		// ok, this is really ugly, but we have to do it this way, since browsers don't render css if you don't set the content-type to text/css
		if($mimeType == 'text/plain' && substr($filePath, -4) == '.css') {
			$mimeType = 'text/css';
		}
		
		
		$this->getResponse()->setHttpHeader('Content-Type', $mimeType);
		return fopen($filePath, 'r');
	}
}

?>